#include "./tcpserver/tcpserver.h"
extern void addsig(int sig,void(handler)(int),bool restart=true);
#define ERR_EXIT(m) \
do\
{\
    perror(m);\
    exit(EXIT_FAILURE);\
}\
while (0);\

void create_daemon(void)
{
    pid_t pid;
    pid = fork();
    if( pid == -1)
        ERR_EXIT("fork error");
    if(pid > 0 )
        exit(EXIT_SUCCESS);
    if(setsid() == -1)
        ERR_EXIT("SETSID ERROR");
    chdir("/");
    int i;
    for( i = 0; i < 3; ++i)
    {
        close(i);
        open("/dev/null", O_RDWR);
        dup(0);
        dup(0);
    }
    umask(0);
    return;
}
int main(int argc,char*argv[])
{
    //守护进程
  // create_daemon();
    /*忽略SIGPIPE信号*/
    addsig(SIGPIPE, SIG_IGN);

    tcpserver *server = new tcpserver;
    
    server->sqlpool_init();
    server->threadpool_init();
    server->event_listen();
    server->epoll_run();
}
